// pages/share/li/li.js
var dateTimePicker = require('../../../module/utils/dateTimePicker.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
title: '',
		listItem: '请选择预约类型',
		pd: 0,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	pd() {
		this.setData({
			pd: 1
		})
	},
	onLoad: function(options) {
		console.log(options)
		this.setData({
			data: options
		})
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					uid: e.data.uid
				})
			}
		})
		var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
		var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
		// 精确到分的处理，将数组的秒去掉
		var lastArray = obj1.dateTimeArray.pop();
		var lastTime = obj1.dateTime.pop();

		this.setData({
			dateTime: obj.dateTime,
			dateTimeArray: obj.dateTimeArray,
			dateTimeArray1: obj1.dateTimeArray,
			dateTime1: obj1.dateTime
		});
	},
	changeDate(e) {
		this.setData({
			date: e.detail.value
		});
	},
	changeTime(e) {
		this.setData({
			time: e.detail.value
		});
	},
	changeDateTime(e) {
		this.setData({
			dateTime: e.detail.value
		});
	},
	changeDateTime1(e) {
		this.setData({
			dateTime1: e.detail.value
		});
	},
	changeDateTimeColumn(e) {
		var arr = this.data.dateTime,
			dateArr = this.data.dateTimeArray;

		arr[e.detail.column] = e.detail.value;
		dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);

		this.setData({
			dateTimeArray: dateArr,
			dateTime: arr
		});
	},
	changeDateTimeColumn1(e) {
		var arr = this.data.dateTime1,
			dateArr = this.data.dateTimeArray1;

		arr[e.detail.column] = e.detail.value;
		dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);

		this.setData({
			dateTimeArray1: dateArr,
			dateTime1: arr
		});
	},
	btn() {
		if (this.data.carNumber != '' && this.data.list != '' && this.data.name != '' && this.data.pd == 1 && this.data.CarType !=
			'' && this.data.mobile != '') {
			let d = this.data.dateTimeArray1
			let o = this.data.dateTime1
			let a = d[0][o[0]] + '-' + d[1][o[1]] + '-' + d[2][o[2]] + ' ' + d[3][o[3]] + ':' + d[4][o[4]]
			console.log(a)
			wx.request({
				url: getApp().globalData.http + 'action=addServerOrder&uid=' + this.data.uid + '&shopid=' + this.data.data.id +
					'&typeid=' +this.data.data.type + '&carNumber=' + this.data.carNumber + '&LinkName=' + this.data.name + '&Ydate=' + a +
					'&CarType=' +this.data.CarType + '&Remark=' + this.data.Remark + '&CarYear=1&mobile=' + this.data.mobile,
				success: (e) => {
					console.log(e)
					let a = e.data.data
					if (e.data.code == 1) {
						wx.reLaunch({
							url: '../../make/over/over?name=' + a.shopName + '&add=' + a.address + '&mobile=' + a.mobile + '&lon=' + a.Longitude +
								'&lat=' + a.Latitude
						})
					}
				}
			})
		} else {
			wx.showToast({
				icon: 'none',
				title: "请正确填写资料"
			})
		}
	},
	Remark(e){
		this.setData({
			Remark:e.detail.value
		})
	},
	CarType(e){
		this.setData({
			CarType:e.detail.value
		})
	},
	carNumber(e){
		this.setData({
			carNumber:e.detail.value
		})
	},
	name(e){
		this.setData({
			name:e.detail.value
		})
	},
	mobile(e){
		this.setData({
			mobile:e.detail.value
		})
	},
})
